package fr.umlv.m2.jee.spij.service.course;

import fr.umlv.m2.jee.spij.persistence.schooling.Course;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Display a course
 *
 * @author lounes
 */
@Component("courseBean")
public class DisplayCourse implements Serializable {

    /**
     * course primary key never display, use to retrieve the course in database
     */
    private long id;

    /**
     * name of coourse
     */
    private String name;

    /**
     * number of matter of course
     */
    private int nbMatter;

    /**
     * training primary key, that the course belong
     */
    private Long training;

    /**
     * obligatory units for courses
     */
    private List<String> obligatoryUnits = new ArrayList<String>();

    /**
     * optional units for courses
     */
    private List<String> optionalUnits = new ArrayList<String>();
    /**
     * Empty constructor
     */
    public DisplayCourse() {

    }
    /**
     * Constructs a DTO course from course.
     * @param course
     */
    public DisplayCourse(Course course) {
        storeDate(course);
    }

    /**
     *  Stores datas from course into DisplayCourse.
     * @param course
     */
    private void storeDate(Course course) {
        if (course.getId() != 0L) {
            setId(course.getId());
        }
        if (!course.getName().isEmpty()) {
            setName(course.getName());
        }
        if (course.getNbMatter() != 0) {
            setNbMatter(course.getNbMatter());
        }
        if (course.getTraining() != 0L) {
            setTraining(course.getTraining());
        }
    }
    /**
     * 
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }
    /**
     * 
     * @return the id of course
     */
    public long getId() {
        return id;
    }
    /**
     * 
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * 
     * @return the name of course
     */
    public String getName() {
        return name;
    }
    /**
     * 
     * @param nbMatter the number of matter to set
     */
    public void setNbMatter(int nbMatter) {
        this.nbMatter = nbMatter;
    }
    /**
     * 
     * @return the number of matter
     */
    public int getNbMatter() {
        return nbMatter;
    }
    /**
     * 
     * @param training the training id to set
     */
    public void setTraining(Long training) {
        this.training = training;
    }
    /**
     * 
     * @return the training id
     */
    public Long getTraining() {
        return training;
    }

    @Override
    public String toString() {
        return name;
    }
    /**
     * 
     * @param obligatoryUnits the list of obligatory units to set
     */
    public void setObligatoryUnits(List<String> obligatoryUnits) {
        this.obligatoryUnits = obligatoryUnits;
    }
    /**
     * 
     * @return the list of obligatory units
     */
    public List<String> getObligatoryUnits() {
        return obligatoryUnits;
    }
    /**
     * 
     * @param optionalUnits the list of optional units to set
     */
    public void setOptionalUnits(List<String> optionalUnits) {
        this.optionalUnits = optionalUnits;
    }
    /**
     * 
     * @return the list of optional units
     */
    public List<String> getOptionalUnits() {
        return optionalUnits;
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#add(java.lang.Object)
     */
    public boolean add0bligatoryUnits(String arg0) {
        return obligatoryUnits.add(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#get(int)
     */
    public String getObligatoryUnits(int arg0) {
        return obligatoryUnits.get(arg0);
    }

    /**
     * @param arg0
     *
     * @return
     *
     * @see java.util.List#remove(int)
     */
    public String removeObligatoryUnits(int arg0) {
        return obligatoryUnits.remove(arg0);
    }

    /**
     * @return
     *
     * @see java.util.List#size()
     */
    public int nbOfObligatoryUnits() {
        return obligatoryUnits.size();
    }


}
